package com.RecipeBook.search;

import java.io.IOException;
import java.util.ArrayList;

import android.database.SQLException;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.RecipeBook.browse.DataBaseHelper;
import com.RecipeBook.common.RecipeActivity;
import com.RecipeBook.main.R;

public class SearchResults extends RecipeActivity
{
	DataBaseHelper myDbHelper;
	
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_results);
		//String[] items = new String[]{"Main Ingredient", "Cuisine", "Course", "Dish Type", "Dietary Considerations"}; 
		
		myDbHelper = new DataBaseHelper(this);
		try {

			myDbHelper.openDataBase();

		}catch(SQLException sqle){

			throw sqle;

		}
		
		
		ArrayList<Integer> recipeIDs = this.getIntent().getIntegerArrayListExtra("rec");
		ArrayList<String> recipeNames = myDbHelper.getNameFromID(recipeIDs);
		String[] items = new String[recipeNames.size()];
		//items = (String[]) recipeNames.toArray();
		for(int x = 0; x < recipeNames.size(); x++)
		{
			items[x] = recipeNames.get(x);
		}
		
		ArrayAdapter<String> ad=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice,items);

		ListView temp = ((ListView)findViewById(R.id.search_result_list));
		temp.setAdapter(ad);
	}
}
